package org.csu.mybigpro.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.csu.mybigpro.domain.Assignment;
import org.csu.mybigpro.persistence.AssignmentMapper;
import org.csu.mybigpro.service.AssignmentService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AssignmentServiceImpl extends ServiceImpl<AssignmentMapper, Assignment> implements AssignmentService {

    @Resource
    private AssignmentMapper assignmentMapper;

    @Override
    public boolean saveAssignment(Assignment assignment) {
        return assignmentMapper.insert(assignment) > 0;
    }

    @Override
    public Assignment getAssignmentById(Long id) {
        return assignmentMapper.selectById(id);
    }

    @Override
    public List<Assignment> getAllAssignments() {
        List<Assignment> assignments = assignmentMapper.selectList(null);
        for (Assignment assignment : assignments) {
            System.out.println(assignment.getFilePath());
        }
        return assignments;
    }

    @Override
    public void updateAssignment(Assignment assignment) {
        assignmentMapper.updateById(assignment);
    }

    @Override
    public void deleteAssignment(Long id) {
        assignmentMapper.deleteById(id);
    }
}